package o;

import androidx.annotation.Nullable;
import java.util.Arrays;

public final class ann<V> {
    private long[] ˊ;
    private int ˋ;
    private int ˎ;
    private V[] ˏ;

    public ann() {
        this(10);
    }

    public ann(int i) {
        this.ˊ = new long[i];
        this.ˏ = ˊ(i);
    }

    public synchronized void ˋ(long j, V v) {
        ˊ(j);
        ˏ();
        ˏ(j, (Object) v);
    }

    public synchronized void ˊ() {
        this.ˋ = 0;
        this.ˎ = 0;
        Arrays.fill(this.ˏ, null);
    }

    @Nullable
    public synchronized V ॱ(long j) {
        return ˏ(j, true);
    }

    @Nullable
    private V ˏ(long j, boolean z) {
        long j2 = Long.MAX_VALUE;
        V v = null;
        while (this.ˎ > 0) {
            long j3 = j - this.ˊ[this.ˋ];
            if (j3 < 0 && (z || (-j3) >= r0)) {
                break;
            }
            V v2 = this.ˏ[this.ˋ];
            this.ˏ[this.ˋ] = null;
            this.ˋ = (this.ˋ + 1) % this.ˏ.length;
            this.ˎ--;
            v = v2;
            j2 = j3;
        }
        return v;
    }

    private void ˊ(long j) {
        if (this.ˎ > 0) {
            if (j <= this.ˊ[((this.ˋ + this.ˎ) - 1) % this.ˏ.length]) {
                ˊ();
            }
        }
    }

    private void ˏ() {
        int length = this.ˏ.length;
        if (this.ˎ >= length) {
            int i = length * 2;
            Object obj = new long[i];
            Object ˊ = ˊ(i);
            length -= this.ˋ;
            System.arraycopy(this.ˊ, this.ˋ, obj, 0, length);
            System.arraycopy(this.ˏ, this.ˋ, ˊ, 0, length);
            if (this.ˋ > 0) {
                System.arraycopy(this.ˊ, 0, obj, length, this.ˋ);
                System.arraycopy(this.ˏ, 0, ˊ, length, this.ˋ);
            }
            this.ˊ = obj;
            this.ˏ = ˊ;
            this.ˋ = 0;
        }
    }

    private void ˏ(long j, V v) {
        int length = (this.ˋ + this.ˎ) % this.ˏ.length;
        this.ˊ[length] = j;
        this.ˏ[length] = v;
        this.ˎ++;
    }

    private static <V> V[] ˊ(int i) {
        return new Object[i];
    }
}
